package com.chebaohui.iqs.service.impl.deal.util;

import com.chebaohui.iqs.entity.base.Owner;

/**
 * 请求接口车主参数判断工具类
 * 
 * @author regas_xie
 *
 */
public class OwnerUtil {
	/**
	 * 判断
	 * 
	 * @param license
	 * @return
	 */
	public static String deal(Owner owner, int type) {
		if (type == 0 && !CompanyUtil.valName(owner.getName()))
			return "姓名错误:" + owner.getName();

		if (type == 0 && !isCard(owner.getIdCard()))
			return "身份证错误:" + owner.getIdCard();

		if (type == 0 && !isPhone(owner.getPhone()))
			return "手机号错误:" + owner.getPhone();

		if (type == 2 && !isAddress(owner.getAddress()))
			return "地址错误:" + owner.getAddress();

		if (type == 3 && !isEmail(owner.getEmail()))
			return "邮箱错误:" + owner.getEmail();

		return "true";
	}

	/**
	 * 地址判断
	 * 
	 * @param msg
	 * @return
	 */
	public static boolean isAddress(String msg) {
		if (StringUtil.isNulls(msg))
			return false;
		return msg.trim().toCharArray().length > 3;
	}

	/**
	 * 手机号码判断(只能判断13、14、15、17、18开头的11位数字)
	 * 
	 * @param msg
	 *            手机号
	 * @return
	 */
	public static boolean isPhone(String msg) {
		if (StringUtil.isNulls(msg))
			return false;
		return StringUtil.valFormat(msg,
				"^(17[0-9]|13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$");
	}

	/**
	 * 邮箱格式判断
	 * 
	 * @param msg
	 *            邮箱
	 * @return
	 */
	public static boolean isEmail(String msg) {
		if (StringUtil.isNulls(msg))
			return false;
		return StringUtil.valFormat(msg, "^(\\w)+(\\.\\w+)*@(\\w)+((\\.\\w+)+)$");
	}

	/**
	 * 身份证格式判断
	 * 
	 * @param msg
	 *            参数
	 * @return
	 */
	public static boolean isCard(String msg) {
		return (StringUtil.valFormat(msg, "^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$") || StringUtil
				.valFormat(msg, "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}[0-9X]$"));
	}
}
